package it.clariter.web.action;

import java.util.List;

import it.clariter.dao.RuoloDAO;
import it.clariter.model.Ruolo;
import it.clariter.web.form.RuoloForm;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class RicercaRuoloAction extends Action {

	
	public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception{
		
		if(request.getSession().getAttribute("utente")==null){
			response.sendRedirect("login.jsp");
		}
		
		HttpSession session = request.getSession();
		
		RuoloForm l = (RuoloForm) form;
		Ruolo ruolo = new Ruolo();
		BeanUtils.copyProperties(ruolo, l);
		
		List<Ruolo> listaRuolo = new RuoloDAO().getList();
		session.setAttribute("ruoli", listaRuolo);
		
		return mapping.findForward("ruolo");
		
	}

}
